#include <string>
#include <vector>

using namespace std;

class Solution {
public:
    int maxScore(string s) {
        vector<int> left(s.size());
        vector<int> right(s.size());
        for (int i = 0, cnt = 0; i < s.size(); i++) {
            if (s[i] == '0') {
                cnt++;
            }
            left[i] = cnt;
        }
        for (int i = s.size() - 1, cnt = 0; i >= 0; i--) {
            if (s[i] == '1') {
                cnt++;
            }
            right[i] = cnt;
        }
        int ans = 0;
        for (int i = 0, len = s.size() - 1; i < len; i++) {
            ans = max(ans, left[i] + right[i + 1]);
        }
        return ans;
    }
};